<!DOCTYPE HTML>
<html>

<head>
  <title>How things are made</title>
  <meta name="description" content="website description" />
  <meta name="keywords" content="website keywords, website keywords" />
  <meta http-equiv="content-type" content="text/html; charset=windows-1252" />
  <link rel="stylesheet" type="text/css" href="style/style.css" title="style" />
</head>

<body>
      <div id="header">
      <div id="logo">
        <div id="logo_text">
          <!-- class="logo_colour", allows you to change the colour of the text -->
          <!--
          <h1><a href="index.php"><span class="logo_colour">Made</span></a></h1>
          <h2>Simple.Different.Creative.</h2>
          -->
          
          
        </div>
</div>
      <div id="menubar">
        <ul id="menu">
          <!-- put class="selected" in the li tag for the selected page - to highlight which page you're on -->
           
           <li class="selected"><a href="index.php">Home</a></li>
          <li><a href="addarticle.php">Add Posts</a></li>
          <li><a href="profileread.php">My Profile</a></li>
          <li><a href="searcharticle.php">Search Posts</a></li>
          <li><a href="searchuser.php">Search User</a></li>
          <li><a href="sendEmail.php">Contact Us</a></li> 
          
        </ul>
      </div>
</div>
    <div id="site_content">
      <div class="sidebar">
        <!-- insert your sidebar items here -->
        <!--
        <h3>Latest User</h3>
		<h4>Click to see the user registered details</h4>
        <h5></h5>
        <p></p>
        <p></p>
        <h4>Sponsored Links</h4>
        <h5></h5>
        <p>This space is reserved for 5 advertisement links</p>
        <h3>Social Media Links</h3>
        <ul>
          <div class="footer_text">
         <div class="foot_pad">
          <div class="link1"><a href="http://www.facebook.com/pages/How-Things-Are-Made/377142059843?sk=wall"> Be a fan on Facebook</a></div>
          <div class="link2"><a href="#">Follow us on Twitter</a></div>
          
          </div>
          </div>
        </ul>
        -->
      </div>
      <div id="content">
        <!-- insert the page content here -->
        
        <?php


if(isset($_POST['submitted']))
{
//$em='/^[\w.-]+@[\w.-]+\.[A-Zaz]{2,6}$/';				  
	$em='/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
	if(!empty($_REQUEST['email']))
	{
		if(preg_match($em,$_REQUEST['email']))
			{
				echo "<br>";
				echo 'Your email is valid';
				echo "<br>";
			}
		else
			{
				echo "<br>";
				echo 'Your email is invalid';
				return;
				echo "<br>";
			}
		$email=$_REQUEST['email'];
	}
	else
	{
		$email=NULL;
		echo "<br>";
		echo 'You forgot to enter you username';
		echo "<br>";
	}
		
	if(!empty($_REQUEST['password']))
	{
		$password=$_REQUEST['password'];
	}
	else
	{
		$pass=NULL;
		echo "<br>";
		echo 'Forgot to enter password';
	}
	
	if($email && $password)
	{
		//echo 'welcome ' . $user;
		//echo "<br>";
		//echo 'Your password is ' . $pass;
		DEFINE ('DB_USER', 'root');
		DEFINE ('DB_PASSWORD', '');
		DEFINE ('DB_HOST', 'localhost');
		DEFINE ('DB_NAME', 'SITEDATABASE');

		// Make the connection:
		$dbc = @mysqli_connect (DB_HOST, DB_USER,DB_PASSWORD, DB_NAME) 
		OR die ('Could not connect to MySQL: ' .mysqli_connect_error() );

		$q = "SELECT email,password FROM users WHERE email='$email' AND password=SHA1('$password')";
    	$r = @mysqli_query ($dbc, $q); // Run the query.
		if (mysqli_num_rows($r) == 1) 
		{
			// Register the values & redirect:
			
			session_start();
			$_SESSION['email'] = $email;
			mysqli_free_result($r);
			mysqli_close($dbc);
			header("Location: http://localhost/MyBlog/index.php");
		}
		else
		{
			echo "Bercinta";
		}
	}
}

?>
        
        
       	<form action="login.php" method="post">
<input type="hidden" name="submitted" value="1" />


<center>
<table>
<tr>
 <td width="83" height="32"><font face="verdana,arial" size=-1>Email:</td>
 <td width="240"><input type="text" value="" name="email" /></td>
</tr>
<tr>
<td height="30"><font face="verdana,arial" size=-1>Password:</td>
<td><input type="password" name="password"></td></tr>
<tr><td height="38"><font face="verdana,arial" size=-1>&nbsp;</td>
<td><font face="verdana,arial" size=-1><input type="submit" value="Submit!" /></td>
</tr>
<tr>
<td colspan=2><font face="verdana,arial" size=-1>&nbsp;</td>
</tr>
<tr>
  <td height="50" colspan=2><font face="verdana,arial" size=-1>Lost your username or password? Click <a href="Forgot password page.html">here</a>!</td>
  </tr>
<tr>
<td height="45" colspan=2><font face="verdana,arial" size=-1>Not member yet? Click <a href="registration.php">here</a> to register.</td>
</tr>
</table>
</center>

</form>

       
      </div>
    </div>
    <div id="content_footer"></div>
    <div id="footer">
      Copyright &copy; 2011 | howthingsaremade.com <a href=" ></a> | <a href="" ></a> | <a href=" ></a>
    </div>
  </div>
<div style="text-align: center; font-size: 0.75em;">  <a href="	http://facebook.com/howthingaremade.com"> Designed for E-Business</a>.</div>
    <script type="text/javascript">
swfobject.registerObject("FlashID");
    </script>
</body>
</html>
